package cn.gov.pbc.dream.pojo.bo;

import cn.gov.pbc.dream.util.DateTimeUtil;
import lombok.Data;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;

import java.io.BufferedReader;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Data
@ToString
public class PIE1Bo {

    private List<BufferedReader> bufferedReaderList = new ArrayList<>();

    private List<ProductTerminationInfo> productTerminationInfoList = new ArrayList<>();

    @Data
    @ToString
    public class ProductTerminationInfo {
        private String bankFinancingProductCode;

        private Date terminationDate;

        private String currencyCode;

        private BigDecimal income;

        private BigDecimal incomeRmb;

        private BigDecimal customerIncome;

        private BigDecimal customerIncomeRmb;

        private BigDecimal customerRateOfReturn;

    }

    public void assembleTerminationInfo(String data){
        ProductTerminationInfo terminationInfo = new ProductTerminationInfo();
        String[] values = data.split("\\|", 8);

        terminationInfo.setBankFinancingProductCode(values[0]);
        terminationInfo.setTerminationDate(DateTimeUtil.strToDate(values[1], DateTimeUtil.DASH_DATE_FORMAT));
        terminationInfo.setCurrencyCode(values[2]);
        if(StringUtils.isNotBlank(values[3])){
            terminationInfo.setIncome(new BigDecimal(values[3]));
        }
        if(StringUtils.isNotBlank(values[4])){
            terminationInfo.setIncomeRmb(new BigDecimal(values[4]));
        }
        if(StringUtils.isNotBlank(values[5])){
            terminationInfo.setCustomerIncome(new BigDecimal(values[5]));
        }
        if(StringUtils.isNotBlank(values[6])){
            terminationInfo.setCustomerIncomeRmb(new BigDecimal(values[6]));
        }

        if(StringUtils.isNotBlank(values[7])){
            terminationInfo.setCustomerRateOfReturn(new BigDecimal(values[7]));
        }
        this.productTerminationInfoList.add(terminationInfo);
    }
}
